package com.graph.factory;

import com.graph.impl.AlgorithmGraph;
import com.graph.base.CommunityFinder;
import com.graph.dto.GeneticAlgorithmDto;

public class AlgorithmFactory implements Provider{
	/**
	 * 遗传算法迭代次数
	 */
	private Integer T1;
	/**
	 * 退火算法迭代次数
	 */
	private Integer T2;
	/**
	 * 退火算法每次迭代次数
	 */
	private Integer L;
	/**
	 * 退火系数
	 */
	private double K;
	/**
	 * 初始化染色体数量
	 */
	private Integer initNum;
    /**
     * 希望划分社区数量
     */
	private Integer communityNum;
	
	@Override
	public CommunityFinder produce(String dataPath,String fileName) {
		return new AlgorithmGraph(T1,T2,L,K,initNum,communityNum,dataPath,fileName);
	}

	/**
	 * 初始化所有所需参数
	 * @Description:TODO
	 * @param T1  遗传算法迭代次数
	 * @param T2 退火算法迭代次数
	 * @param L 退火算法每次迭代次数
	 * @param K 退火算法退火率
	 * @param initNum  初始化染色体个数
	 * @param communityNum  期望分割社区数目
	 * @author: wujiang
	 * @throws Exception 
	 * @time:2017-3-5 下午2:24:01
	 */
	public AlgorithmFactory(GeneticAlgorithmDto dto) throws Exception {
		if(!dto.isFinishbind()){
			throw new Exception("参数错误！");
		}
		this.T1=dto.getT1();
		this.T2=dto.getT2();
		this.L=dto.getL();
		this.K=dto.getK();
		this.initNum=dto.getInitNum();
		this.communityNum=dto.getCommunityNum();
	}
	
	public AlgorithmFactory() {
		this.T1=100;
		this.T2=1000;
		this.L=10;
		this.K=0.99;
		this.initNum=500;
		this.communityNum=2;
	}
}
